from .bot_func import *
from flask import current_app as bot

class ThreadName(threading.Thread):
    def __init__(self, arg):
        threading.Thread.__init__(self)
        self.arg = arg

    def run(self):
        pass

class BaseSession():
    def __init__(self, info):
        self.info = info
        self.robot_wxid = self.info.get('robot_wxid', '')
        self.from_wxid = self.info.get('from_wxid', '')

    def send_text_msg(self, msg):
        send_text_msg(self.robot_wxid, self.from_wxid, msg)

    def send_group_at_msg(self, msg):
        print(self.info['event'])
        if self.info['event'] == 'group_msg':
            send_group_at_msg(self.robot_wxid, self.from_wxid, self.info['final_from_wxid'], self.info['final_from_name'], msg)
        elif self.info['event'] == 'friend_msg':
            self.send_text_msg(msg)

    def send_image_msg(self, path):
        send_image_msg(self.robot_wxid, self.from_wxid, path)

    def send_video_msg(self, path):
        send_video_msg(self.robot_wxid, self.from_wxid, path)

    def send_file_msg(self, path):
        send_file_msg(self.robot_wxid, self.from_wxid, path)

    def send_emoji_msg(self, path):
        send_emoji_msg(self.robot_wxid, self.from_wxid, path)

    def send_link_msg(self, title, text, target_url, pic_url, icon_url):
        send_link_msg(self.robot_wxid, self.from_wxid, title, text, target_url, pic_url, icon_url)

    def send_music_msg(self, name, music_type):
        send_music_msg(self.robot_wxid, self.from_wxid, name, music_type)

    def accept_transfer(self):
        accept_transfer(self.robot_wxid, self.from_wxid, self.info['json_msg'])

    def agree_group_invite(self):
        agree_group_invite(self.robot_wxid, self.info['json_msg'])

    def modify_friend_note(self, note):
        modify_friend_note(self.robot_wxid, self.from_wxid, note)

    def remove_group_member(self, member_wxid):
        remove_group_member(self.robot_wxid, self.from_wxid, member_wxid)

    def modify_group_name(self, group_name):
        modify_group_name(self.robot_wxid, self.from_wxid, group_name)

    def delete_friend(self, friend_wxid):
        delete_friend(self.robot_wxid, friend_wxid)

    def modify_group_notice(self, notice):
        modify_group_notice(self.robot_wxid, self.from_wxid, notice)

    def building_group(self, friends):
        building_group(self.robot_wxid, friends)

    def quit_group(self):
        quit_group(self.robot_wxid, self.from_wxid)

    def invite_in_group(self, friend_wxid):
        invite_in_group(self.robot_wxid, self.from_wxid, friend_wxid)

    def get_robot_name(self):
        get_robot_name(self.robot_wxid)

    def get_robot_headimgurl(self):
        get_robot_headimgurl(self.robot_wxid)

    def get_friend_list(self, is_refresh=0):
        get_friend_list(self.robot_wxid, is_refresh=0)

    def get_group_list(self, is_refresh=0):
        get_group_list(self.robot_wxid, is_refresh=0)

    def get_group_member(self, member_wxid, is_refresh=0):
        get_group_member(self.robot_wxid, self._wxid, member_wxid, is_refresh=0)

    def get_group_member_list(self, is_refresh=0):
        get_group_member_list(self.robot_wxid, self._wxid, is_refresh=0)

class CommandSession(BaseSession):
    def __init__(self, info):
        super().__init__(info)

class RequestSession(BaseSession):
    def __init__(self, info, json_msg):
        super().__init__(info)
        self.json_msg = json_msg

    def agree_friend_verify(self):
        agree_friend_verify(self.robot_wxid, self.json_msg)

class NoticeSession(BaseSession):
    def __init__(self, info, json_msg):
        super().__init__(info)
        self.json_msg = json_msg

